import Request from '../utils/request.js'
let request = new Request().http

// 按需引入的 请求头
export const getUserInfo = function(data) {
	return request({
		url: "api/auth/login",
		method: "POST",
		data
	})
}
// 注册
export const getregister = function(data) {
	return request({
		url: "api/auth/register",
		method: "POST",
		data
	})
}
export const deltlogout = function() {
	return request({
		url: "api/auth/logout",
		method: "POST",
	})
}
export const getUserdata = function() {
	return request({
		url: "api/user",
	})
}

export const getindex = function() {
	return request({
		url: "api/index",
	})
}
export const getosstoken = function() {
	return request({
		url: "api/auth/oss/token",
	})
}
// /更新用户头像
export const getavatar = function(data) {
	return request({
		url: "api/user/avatar",
		method: "post",
		data
	})
}
export const upuser = function(data) {
	return request({
		url: "api/user",
		method: 'put',
		data
	})
}
// 省市县
export const getcity = function(data) {
	return request({
		url: 'api/city',
		data
	})
}
// 增加收货地址
export const addaddress = function(data) {
	return request({
		method: "POST",
		url: 'api/address',
		data
	})
}
// 获取地址
export const getaddress = function(data) {
	return request({
		url: 'api/address',
		data
	})
}
// 删除地址
export const deladdress = function(address) {
	return request({
		method: 'DELETE',
		url: 'api/address/' + address,
	})
}
// 收藏
export const getcollects = function(data) {
	return request({
		url: 'api/collects',
		data
	})
}
// 获取购物车商品
// export const getcarts = function() {
// 	return request({
// 		url: "api/carts",
// 	})
// }
export const getcarts = function(data) {
	return request({
		url: "api/carts?include=goods",
		data
	})
}
// export const getcarts = function() {
// 	return request({
// 		url: "api/carts?include=goods",
// 	})
// }
// 购物车数量变化
export const upcartnum = function(cart, num) {
	return request({
		method: "PUT",
		url: `api/carts/${cart}?num=` + num,
	})
}
// 选中
export const upchecked = function(data) {
	return request({
		method: "PATCH",
		url: "api/carts/checked",
		data
	})
}
// /api/carts/checked
// api/carts/15100?num=8
// 提交订单
export const addorders = function(address_id) {
	return request({
		url: "api/orders?address_id=" + address_id,
		method: "post",
	})
}
// 订单预览
export const getpreview = function() {
	return request({
		url: "api/orders/preview"
	})
}
// 订单列表
export const getorders = function(data) {
	return request({
		url: "api/orders?include=orderDetails.goods",
		data
	})
}
// 订单详情
export const getordersdetails = function(order) {
	return request({
		url: `api/orders/${order}?include=orderDetails.goods,address`
	})
}
// 支付

export const getpaytest = function(order) {
	return request({
		method: 'PATCH',
		url: `api/orders/${order}/paytest?type=aliyun`
	})
}
// 获取二维码
export const getpay = function(order) {
	return request({
		url: `api/orders/${order}/pay?type=aliyun`
	})
}
